/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package airtrafficcontrol.Clearence_Delivery;

import MinaClient.MinaClient;
import MinaClient.MinaClientInterface;
import Toolkit.DataHandler;
import Toolkit.InfoTimerTask;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JButton;
import javax.swing.JComponent;
import Simulation.*;

/**
 *
 * @author franc_000
 */
public class Clearence_Delivery extends javax.swing.JFrame {

    /**
     * Creates new form NewJFrame
     */
    public Clearence_Delivery(String username) {
        initComponents();
        this.setLocationRelativeTo(null);
        
        this.g_username = username;
        jTextField_CD_Username.setText(username);
        Timer timer = new Timer();
        TimerTask weatherUpdate = new InfoTimerTask(jTextArea_CD_Weather);
        TimerTask runwayUpdate = new InfoTimerTask(jTextArea_CD_Runway);
        //timer.schedule(weatherUpdate, 500L, 2000L);
        //timer.schedule(runwayUpdate, 500L, 2000L);
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea_CD_Weather = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea_CD_Runway = new javax.swing.JTextArea();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextArea_CD_FlightInfo = new javax.swing.JTextArea();
        jLabel_CD_ApproveQueue = new javax.swing.JLabel();
        jLabel_CD_AwaitQueue = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextArea_CD_TakingOffQueue = new javax.swing.JTextArea();
        jLabel_CD_TakeOffQueue = new javax.swing.JLabel();
        jButton_CD_Approve_1 = new javax.swing.JButton();
        jButton_CD_Approve_2 = new javax.swing.JButton();
        jButton_CD_Approve_3 = new javax.swing.JButton();
        jButton_CD_Approve_4 = new javax.swing.JButton();
        jButton_CD_Await_1 = new javax.swing.JButton();
        jButton_CD_Await_2 = new javax.swing.JButton();
        jButton_CD_Await_3 = new javax.swing.JButton();
        jButton_CD_Await_4 = new javax.swing.JButton();
        jButton_CD_Await_5 = new javax.swing.JButton();
        jButton_CD_Await_6 = new javax.swing.JButton();
        jButton_CD_Await_7 = new javax.swing.JButton();
        jTextField_CD_UserID = new javax.swing.JTextField();
        jTextField_CD_Username = new javax.swing.JTextField();
        jButton1_CD_Approve = new javax.swing.JButton();
        jLabel_CD_Squawk = new javax.swing.JLabel();
        jButton_CD_StandBy = new javax.swing.JButton();
        jButton_CD_ContactGround = new javax.swing.JButton();
        jTextField_CD_Squawk = new javax.swing.JTextField();
        jButton_CD_ConfirmSquawk = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTextArea_CD_RealTimeInfo = new javax.swing.JTextArea();
        jScrollPane7 = new javax.swing.JScrollPane();
        jTextArea_CD_Suggestion = new javax.swing.JTextArea();
        jButton_CD_Emergency = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(1100, 700));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N
        jLabel1.setText("Clearence Delivery Control System");

        jTextArea_CD_Weather.setEditable(false);
        jTextArea_CD_Weather.setColumns(20);
        jTextArea_CD_Weather.setRows(5);
        jTextArea_CD_Weather.setText("Weather Information");
        jTextArea_CD_Weather.setInheritsPopupMenu(true);
        jTextArea_CD_Weather.setMaximumSize(new java.awt.Dimension(205, 104));
        jTextArea_CD_Weather.setMinimumSize(new java.awt.Dimension(205, 104));
        jTextArea_CD_Weather.setName("WeatherInfo"); // NOI18N
        jTextArea_CD_Weather.setPreferredSize(new java.awt.Dimension(205, 104));
        jScrollPane1.setViewportView(jTextArea_CD_Weather);

        jTextArea_CD_Runway.setEditable(false);
        jTextArea_CD_Runway.setColumns(20);
        jTextArea_CD_Runway.setRows(5);
        jTextArea_CD_Runway.setText("Runway State");
        jTextArea_CD_Runway.setMaximumSize(new java.awt.Dimension(205, 2147483647));
        jTextArea_CD_Runway.setMinimumSize(new java.awt.Dimension(205, 24));
        jTextArea_CD_Runway.setName("RunwayState"); // NOI18N
        jScrollPane2.setViewportView(jTextArea_CD_Runway);

        jTextArea_CD_FlightInfo.setEditable(false);
        jTextArea_CD_FlightInfo.setColumns(20);
        jTextArea_CD_FlightInfo.setRows(5);
        jTextArea_CD_FlightInfo.setText("Flight Information");
        jScrollPane3.setViewportView(jTextArea_CD_FlightInfo);

        jLabel_CD_ApproveQueue.setFont(new java.awt.Font("宋体", 1, 12)); // NOI18N
        jLabel_CD_ApproveQueue.setText("Delivery Approve Queue");
        jLabel_CD_ApproveQueue.setMaximumSize(new java.awt.Dimension(160, 23));
        jLabel_CD_ApproveQueue.setMinimumSize(new java.awt.Dimension(160, 23));
        jLabel_CD_ApproveQueue.setPreferredSize(new java.awt.Dimension(160, 23));

        jLabel_CD_AwaitQueue.setFont(new java.awt.Font("宋体", 1, 12)); // NOI18N
        jLabel_CD_AwaitQueue.setText("Delivery await Queue");
        jLabel_CD_AwaitQueue.setMaximumSize(new java.awt.Dimension(160, 23));
        jLabel_CD_AwaitQueue.setMinimumSize(new java.awt.Dimension(160, 23));
        jLabel_CD_AwaitQueue.setName(""); // NOI18N
        jLabel_CD_AwaitQueue.setPreferredSize(new java.awt.Dimension(160, 23));

        jTextArea_CD_TakingOffQueue.setEditable(false);
        jTextArea_CD_TakingOffQueue.setColumns(20);
        jTextArea_CD_TakingOffQueue.setRows(5);
        jScrollPane4.setViewportView(jTextArea_CD_TakingOffQueue);

        jLabel_CD_TakeOffQueue.setFont(new java.awt.Font("宋体", 1, 12)); // NOI18N
        jLabel_CD_TakeOffQueue.setText("Flight Taking-off Queue");

        jButton_CD_Approve_1.setText("SQ827 20R STD:13:09");
        jButton_CD_Approve_1.setMaximumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Approve_1.setMinimumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Approve_1.setPreferredSize(new java.awt.Dimension(160, 23));

        jButton_CD_Approve_2.setText("AK753 20R STD:13:13");
        jButton_CD_Approve_2.setMaximumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Approve_2.setMinimumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Approve_2.setPreferredSize(new java.awt.Dimension(160, 23));

        jButton_CD_Approve_3.setText("SQ941 20C STD:13:17");
        jButton_CD_Approve_3.setMaximumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Approve_3.setMinimumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Approve_3.setPreferredSize(new java.awt.Dimension(160, 23));

        jButton_CD_Approve_4.setText("CX2691 20R STD 13:19");
        jButton_CD_Approve_4.setMaximumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Approve_4.setMinimumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Approve_4.setPreferredSize(new java.awt.Dimension(160, 23));

        jButton_CD_Await_1.setText("SQ931 20R STD:13:32");
        jButton_CD_Await_1.setMaximumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_1.setMinimumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_1.setName("jButton_CD_Await_1"); // NOI18N
        jButton_CD_Await_1.setPreferredSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CD_Await_1ActionPerformed(evt);
            }
        });

        jButton_CD_Await_2.setText("AK713 20R STD:13:37");
        jButton_CD_Await_2.setMaximumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_2.setMinimumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_2.setName("jButton_CD_Await_2"); // NOI18N
        jButton_CD_Await_2.setPreferredSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CD_Await_2ActionPerformed(evt);
            }
        });

        jButton_CD_Await_3.setText("MI151 20C STD:13:41");
        jButton_CD_Await_3.setMaximumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_3.setMinimumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_3.setName("jButton_CD_Await_3"); // NOI18N
        jButton_CD_Await_3.setPreferredSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CD_Await_3ActionPerformed(evt);
            }
        });

        jButton_CD_Await_4.setText("QZ361 20R STD:13:42");
        jButton_CD_Await_4.setMaximumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_4.setMinimumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_4.setName("jButton_CD_Await_4"); // NOI18N
        jButton_CD_Await_4.setPreferredSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CD_Await_4ActionPerformed(evt);
            }
        });

        jButton_CD_Await_5.setText("MH623 20C STD:13:45");
        jButton_CD_Await_5.setMaximumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_5.setMinimumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_5.setName("jButton_CD_Await_5"); // NOI18N
        jButton_CD_Await_5.setPreferredSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CD_Await_5ActionPerformed(evt);
            }
        });

        jButton_CD_Await_6.setText("SQ7365 20R STD:13:50");
        jButton_CD_Await_6.setMaximumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_6.setMinimumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_6.setName("jButton_CD_Await_6"); // NOI18N
        jButton_CD_Await_6.setPreferredSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CD_Await_6ActionPerformed(evt);
            }
        });

        jButton_CD_Await_7.setText("TR2183 20C STD:13:53");
        jButton_CD_Await_7.setMaximumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_7.setMinimumSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_7.setName("jButton_CD_Await_7"); // NOI18N
        jButton_CD_Await_7.setPreferredSize(new java.awt.Dimension(160, 23));
        jButton_CD_Await_7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CD_Await_7ActionPerformed(evt);
            }
        });

        jTextField_CD_UserID.setEditable(false);
        jTextField_CD_UserID.setText("Controller ID:");
        jTextField_CD_UserID.setMaximumSize(new java.awt.Dimension(160, 23));
        jTextField_CD_UserID.setMinimumSize(new java.awt.Dimension(160, 23));
        jTextField_CD_UserID.setPreferredSize(new java.awt.Dimension(160, 23));

        jTextField_CD_Username.setEditable(false);
        jTextField_CD_Username.setText("Controller Name:");

        jButton1_CD_Approve.setText("Delivery Approve");
        jButton1_CD_Approve.setMaximumSize(new java.awt.Dimension(160, 23));
        jButton1_CD_Approve.setMinimumSize(new java.awt.Dimension(160, 23));
        jButton1_CD_Approve.setPreferredSize(new java.awt.Dimension(160, 23));
        jButton1_CD_Approve.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1_CD_ApproveActionPerformed(evt);
            }
        });

        jLabel_CD_Squawk.setFont(new java.awt.Font("宋体", 1, 12)); // NOI18N
        jLabel_CD_Squawk.setText("Squawk:");

        jButton_CD_StandBy.setText("Stand-by");
        jButton_CD_StandBy.setMaximumSize(new java.awt.Dimension(160, 23));
        jButton_CD_StandBy.setMinimumSize(new java.awt.Dimension(160, 23));
        jButton_CD_StandBy.setPreferredSize(new java.awt.Dimension(160, 23));
        jButton_CD_StandBy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CD_StandByActionPerformed(evt);
            }
        });

        jButton_CD_ContactGround.setText("Contact Ground");
        jButton_CD_ContactGround.setMaximumSize(new java.awt.Dimension(160, 23));
        jButton_CD_ContactGround.setMinimumSize(new java.awt.Dimension(160, 23));
        jButton_CD_ContactGround.setPreferredSize(new java.awt.Dimension(160, 23));

        jTextField_CD_Squawk.setText("2321");

        jButton_CD_ConfirmSquawk.setText("Confirm Squawk");

        jTextArea_CD_RealTimeInfo.setColumns(20);
        jTextArea_CD_RealTimeInfo.setRows(5);
        jTextArea_CD_RealTimeInfo.setText("Real-time information");
        jScrollPane6.setViewportView(jTextArea_CD_RealTimeInfo);

        jTextArea_CD_Suggestion.setColumns(20);
        jTextArea_CD_Suggestion.setRows(5);
        jTextArea_CD_Suggestion.setText("Suggestion...");
        jScrollPane7.setViewportView(jTextArea_CD_Suggestion);

        jButton_CD_Emergency.setText("Emergency");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 510, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton_CD_Approve_4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jButton_CD_ConfirmSquawk, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jButton_CD_StandBy, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(0, 0, Short.MAX_VALUE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel_CD_Squawk, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextField_CD_Squawk, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton1_CD_Approve, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(18, 18, 18)
                                .addComponent(jButton_CD_ContactGround, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 511, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel_CD_ApproveQueue, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton_CD_Approve_1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton_CD_Approve_2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton_CD_Approve_3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jTextField_CD_UserID, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane7))))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton_CD_Await_2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton_CD_Await_1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel_CD_AwaitQueue, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton_CD_Await_3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton_CD_Await_4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton_CD_Await_5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton_CD_Await_6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton_CD_Await_7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel_CD_TakeOffQueue, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(jButton_CD_Emergency, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jTextField_CD_Username, javax.swing.GroupLayout.PREFERRED_SIZE, 343, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField_CD_UserID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField_CD_Username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel_CD_AwaitQueue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel_CD_ApproveQueue, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel_CD_TakeOffQueue))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jButton_CD_Approve_1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButton_CD_Await_1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jButton_CD_Approve_2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButton_CD_Await_2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jButton_CD_Approve_3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButton_CD_Await_3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jButton_CD_Approve_4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButton_CD_Await_4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addComponent(jButton_CD_Await_5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton_CD_Await_6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton_CD_Await_7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(jScrollPane4))
                        .addGap(30, 30, 30))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton_CD_ContactGround, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1_CD_Approve, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField_CD_Squawk, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel_CD_Squawk))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 47, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton_CD_Emergency)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jButton_CD_StandBy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButton_CD_ConfirmSquawk))
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_CD_Await_1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CD_Await_1ActionPerformed
        // TODO add your handling code here:
        airplaneButtonHandler(jButton_CD_Await_1);
        g_currentButton = jButton_CD_Await_1;
    }//GEN-LAST:event_jButton_CD_Await_1ActionPerformed

    private void jButton_CD_Await_2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CD_Await_2ActionPerformed
        // TODO add your handling code here:
        airplaneButtonHandler(jButton_CD_Await_2);
        g_currentButton = jButton_CD_Await_2;
    }//GEN-LAST:event_jButton_CD_Await_2ActionPerformed

    private void jButton_CD_Await_4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CD_Await_4ActionPerformed
        // TODO add your handling code here:
        airplaneButtonHandler(jButton_CD_Await_4);
        g_currentButton = jButton_CD_Await_4;
    }//GEN-LAST:event_jButton_CD_Await_4ActionPerformed

    private void jButton_CD_Await_3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CD_Await_3ActionPerformed
        // TODO add your handling code here:
        airplaneButtonHandler(jButton_CD_Await_3);
        g_currentButton = jButton_CD_Await_3;
    }//GEN-LAST:event_jButton_CD_Await_3ActionPerformed

    private void jButton_CD_Await_5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CD_Await_5ActionPerformed
        // TODO add your handling code here:
        airplaneButtonHandler(jButton_CD_Await_5);
        g_currentButton = jButton_CD_Await_5;
    }//GEN-LAST:event_jButton_CD_Await_5ActionPerformed

    private void jButton_CD_Await_6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CD_Await_6ActionPerformed
        // TODO add your handling code here:
        airplaneButtonHandler(jButton_CD_Await_6);
        g_currentButton = jButton_CD_Await_6;
    }//GEN-LAST:event_jButton_CD_Await_6ActionPerformed

    private void jButton_CD_Await_7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CD_Await_7ActionPerformed
        // TODO add your handling code here:
        airplaneButtonHandler(jButton_CD_Await_7);
        g_currentButton = jButton_CD_Await_7;
    }//GEN-LAST:event_jButton_CD_Await_7ActionPerformed

    private void jButton_CD_StandByActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CD_StandByActionPerformed
        // TODO add your handling code here:
        MinaClientInterface mci = new MinaClient();
        mci.createConnect("127.0.0.1",9123);
        //mci.sendMessage("Modify;"+"Airplane;"+"Status;"+"CD_StandBy");
        
        g_currentButton.setForeground(Color.red);
    }//GEN-LAST:event_jButton_CD_StandByActionPerformed

    private void jButton1_CD_ApproveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1_CD_ApproveActionPerformed
        // TODO add your handling code here:
        MinaClientInterface mci = new MinaClient();
        mci.createConnect("127.0.0.1",9123);
        //mci.sendMessage("Modify;"+"Airplane;"+"Status;"+"CD_Approve");
              
        
    }//GEN-LAST:event_jButton1_CD_ApproveActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        
        System.out.println("Windows closing!!"); 
        MinaClientInterface mci = new MinaClient();
        mci.createConnect("127.0.0.1",9123);
        mci.sendMessage("Update;Login;"+g_username+";offline");
        System.exit(0); 
    }//GEN-LAST:event_formWindowClosing

    void airplaneButtonHandler(JButton jbutton) {
        jTextArea_CD_FlightInfo.setText("");
        
        switch(jbutton.getName()) {
            case "jButton_CD_Await_1":
                getAirplaneInfo("JT150");
                break;
            case "jButton_CD_Await_2":
                getAirplaneInfo("JT151");
                break;
            case "jButton_CD_Await_3":
                getAirplaneInfo("JT151");
                break;
            case "jButton_CD_Await_4":
                getAirplaneInfo("JT151");
                break;
            case "jButton_CD_Await_5":
                getAirplaneInfo("JT151");
                break;
            case "jButton_CD_Await_6":
                getAirplaneInfo("JT151");
                break; 
            case "jButton_CD_Await_7":
                getAirplaneInfo("JT151");
                break;   
            default:
                break;
        }
        
        g_currentButton = jbutton;
    }
    
    void getAirplaneInfo(String flight) {
        MinaClientInterface mci = new MinaClient();
        mci.createConnect("127.0.0.1",9123);
        mci.sendMessage("Query;Flight;"+flight+";0");
        
        String tempRecevieMessage = mci.receiveMessage();
        
        ArrayList<String> tempFlight;
        tempFlight = new DataHandler().flightDataHandler(tempRecevieMessage,
                                                       jTextArea_CD_FlightInfo);
        g_Flight = tempFlight.get(0);
        g_Registration = tempFlight.get(1);
        System.out.println(tempRecevieMessage);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Clearence_Delivery.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Clearence_Delivery.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Clearence_Delivery.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Clearence_Delivery.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(() -> {
            new Clearence_Delivery("chencheng").setVisible(true);
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1_CD_Approve;
    private javax.swing.JButton jButton_CD_Approve_1;
    private javax.swing.JButton jButton_CD_Approve_2;
    private javax.swing.JButton jButton_CD_Approve_3;
    private javax.swing.JButton jButton_CD_Approve_4;
    private javax.swing.JButton jButton_CD_Await_1;
    private javax.swing.JButton jButton_CD_Await_2;
    private javax.swing.JButton jButton_CD_Await_3;
    private javax.swing.JButton jButton_CD_Await_4;
    private javax.swing.JButton jButton_CD_Await_5;
    private javax.swing.JButton jButton_CD_Await_6;
    private javax.swing.JButton jButton_CD_Await_7;
    private javax.swing.JButton jButton_CD_ConfirmSquawk;
    private javax.swing.JButton jButton_CD_ContactGround;
    private javax.swing.JButton jButton_CD_Emergency;
    private javax.swing.JButton jButton_CD_StandBy;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel_CD_ApproveQueue;
    private javax.swing.JLabel jLabel_CD_AwaitQueue;
    private javax.swing.JLabel jLabel_CD_Squawk;
    private javax.swing.JLabel jLabel_CD_TakeOffQueue;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JTextArea jTextArea_CD_FlightInfo;
    private javax.swing.JTextArea jTextArea_CD_RealTimeInfo;
    private javax.swing.JTextArea jTextArea_CD_Runway;
    private javax.swing.JTextArea jTextArea_CD_Suggestion;
    private javax.swing.JTextArea jTextArea_CD_TakingOffQueue;
    private javax.swing.JTextArea jTextArea_CD_Weather;
    private javax.swing.JTextField jTextField_CD_Squawk;
    private javax.swing.JTextField jTextField_CD_UserID;
    private javax.swing.JTextField jTextField_CD_Username;
    // End of variables declaration//GEN-END:variables

    private String g_Flight;
    private String g_Registration;
    private JButton g_currentButton;
    private String g_username;
    private String g_destination;
}
